home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / BenchMarks / Dhrystone / dhry_global.h next >
Text File  |  1993-01-25  |  14KB  |  424 lines

  1. /*
  2.  ****************************************************************************
  3.  *
  4.  *             "DHRYSTONE" Benchmark Program
  5.  *             -----------------------------
  6.  *                                          
  7.  *  Version:    C, Version 2.0
  8.  *                                          
  9.  *  File:    dhry_global.h (part 1 of 3)
  10.  *
  11.  *  Date:    March 3, 1988
  12.  *
  13.  *  Author:    Reinhold P. Weicker
  14.  *            Siemens    AG, E STE 35
  15.  *            Postfach 3240
  16.  *            8520 Erlangen
  17.  *            Germany    (West)
  18.  *                Phone:    [xxx-49]-9131-7-20330
  19.  *                    (8-17 Central European Time)
  20.  *                Usenet:    ..!mcvax!unido!estevax!weicker
  21.  *
  22.  *        Original Version (in Ada) published in
  23.  *        "Communications    of the ACM" vol. 27., no. 10 (Oct. 1984),
  24.  *        pp. 1013 - 1030, together with the statistics
  25.  *        on which the distribution of statements    etc. is    based.
  26.  *
  27.  *        In this    C version, the following C library functions are used:
  28.  *        - strcpy, strcmp (inside the measurement loop)
  29.  *        - printf, scanf    (outside the measurement loop)
  30.  *        In addition, UNIX system calls "times ()" or "time ()"
  31.  *        are used for execution time measurement. For measurements
  32.  *        on other systems, these    calls have to be changed.
  33.  *
  34.  *  Collection of Results:
  35.  *        Reinhold Weicker (address see above) and
  36.  *        
  37.  *        Rick Richardson
  38.  *        PC Research. Inc.
  39.  *        94 Apple Orchard Drive
  40.  *        Tinton Falls, NJ 07724
  41.  *            Phone:    (201) 834-1378 (9-17 EST)        
  42.  *            Usenet:    ...!seismo!uunet!pcrat!rick
  43.  *
  44.  *    Please send results to Reinhold    Weicker    and/or Rick Richardson.
  45.  *    Complete information should be given on    hardware and software used.
  46.  *    Hardware information includes: Machine type, CPU, type and size
  47.  *    of caches; for microprocessors:    clock frequency, memory    speed
  48.  *    (number    of wait    states).
  49.  *    Software information includes: Compiler    (and runtime library)
  50.  *    manufacturer and version, compilation switches,    OS version.
  51.  *    The Operating System version may give an indication about the
  52.  *    compiler; Dhrystone itself performs no OS calls    in the measurement loop.
  53.  *
  54.  *    The complete output generated by the program should be mailed
  55.  *    such that at least some    checks for correctness can be made.
  56.  *
  57.  ***************************************************************************
  58.  *
  59.  *  History:    This version C/2.0 has been made for two reasons:
  60.  *
  61.  *        1) There is an obvious need for    a common C version of
  62.  *        Dhrystone, since C is at present the most popular system
  63.  *        programming language for the class of processors
  64.  *        (microcomputers, minicomputers)    where Dhrystone    is used    most.
  65.  *        There should be, as far    as possible, only one C    version    of
  66.  *        Dhrystone such that results can    be compared without
  67.  *        restrictions. In the past, the C versions distributed
  68.  *        by Rick    Richardson (Version 1.1) and by    Reinhold Weicker
  69.  *        had small (though not significant) differences.
  70.  *
  71.  *        2) As far as it    is possible without changes to the Dhrystone
  72.  *        statistics, optimizing compilers should    be prevented from
  73.  *        removing significant statements.
  74.  *
  75.  *        This C version has been    developed in cooperation with
  76.  *        Rick Richardson    (Tinton    Falls, NJ), it incorporates many
  77.  *        ideas from the "Version    1.1" distributed previously by
  78.  *        him over the UNIX network Usenet.
  79.  *        I also thank Chaim Benedelac (National Semiconductor),
  80.  *        David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
  81.  *        Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
  82.  *        for their help with comments on    earlier    versions of the
  83.  *        benchmark.
  84.  *
  85.  *  Changes:    In the initialization part, this version follows mostly
  86.  *        Rick Richardson's version distributed via Usenet, not the
  87.  *        version    distributed earlier via    floppy disk by Reinhold    Weicker.
  88.  *        As a concession    to older compilers, names have been made
  89.  *        unique within the first    8 characters.
  90.  *        Inside the measurement loop, this version follows the
  91.  *        version    previously distributed by Reinhold Weicker.
  92.  *
  93.  *        At several places in the benchmark, code has been added,
  94.  *        but within the measurement loop    only in    branches that 
  95.  *        are not    executed. The intention    is that    optimizing compilers
  96.  *        should be prevented from moving    code out of the    measurement
  97.  *        loop, or from removing code altogether.    Since the statements
  98.  *        that are executed within the measurement loop have NOT been
  99.  *        changed, the numbers defining the "Dhrystone distribution"
  100.  *        (distribution of statements, operand types and locality)
  101.  *        still hold. Except for sophisticated optimizing    compilers,
  102.  *        execution times    for this version should    be the same as
  103.  *        for previous versions.
  104.  *        
  105.  *        Since it has proven difficult to subtract the time for the
  106.  *        measurement loop overhead in a correct way, the    loop check
  107.  *        has been made a    part of    the benchmark. This does have
  108.  *        an impact - though a very minor    one - on the distribution
  109.  *        statistics which have been updated for this version.
  110.  *
  111.  *        All changes within the measurement loop    are described
  112.  *        and discussed in the companion paper "Rationale    for
  113.  *        Dhrystone version 2".
  114.  *
  115.  *        Because    of the self-imposed limitation that the    order and
  116.  *        distribution of    the executed statements    should not be
  117.  *        changed, there are still cases where optimizing    compilers
  118.  *        may not    generate code for some statements. To a    certain
  119.  *        degree,    this is    unavoidable for    small synthetic    benchmarks.
  120.  *        Users of the benchmark are advised to check code listings
  121.  *        whether    code is    generated for all statements of    Dhrystone.
  122.  *
  123.  ***************************************************************************
  124.  *
  125.  * Defines:    The following "Defines"    are possible:
  126.  *        -DREG=register        (default: Not defined)
  127.  *            As an approximation to what an average C programmer
  128.  *            might do, the "register" storage class is applied
  129.  *            (if enabled by -DREG=register)
  130.  *            - for local variables, if they are used    (dynamically)
  131.  *              five or more times
  132.  *            - for parameters if they are used (dynamically)
  133.  *              six or more times
  134.  *            Note that an optimal "register"    strategy is
  135.  *            compiler-dependent, and    that "register"    declarations
  136.  *            do not necessarily lead    to faster execution.
  137.  *        -DNOSTRUCTASSIGN    (default: Not defined)
  138.  *            Define if the C    compiler does not support
  139.  *            assignment of structures.
  140.  *        -DNOENUMS        (default: Not defined)
  141.  *            Define if the C    compiler does not support
  142.  *            enumeration types.
  143.  *        -DTIMES            (default)
  144.  *        -DTIME
  145.  *            The "times" function of    UNIX (returning    process    times)
  146.  *            or the "time" function (returning wallclock time)
  147.  *            is used    for measurement. 
  148.  *            For single user    machines, "time    ()" is adequate. For
  149.  *            multi-user machines where you cannot get single-user
  150.  *            access,    use the    "times ()" function. If    you have
  151.  *            neither, use a stopwatch in the    dead of    night.
  152.  *            "printf"s are provided marking the points "Start Timer"
  153.  *            and "Stop Timer". DO NOT use the UNIX "time(1)"
  154.  *            command, as this will measure the total    time to
  155.  *            run this program, which    will (erroneously) include
  156.  *            the time to allocate storage (malloc) and to perform
  157.  *            the initialization.
  158.  *        -DHZ=nnn        (default: 60)
  159.  *            The function "times" returns process times in
  160.  *            1/HZ seconds, with HZ =    60 for most systems.
  161.  *            CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY
  162.  *            THE DEFAULT VALUE.
  163.  *
  164.  ***************************************************************************
  165.  *
  166.  *  Compilation    model and measurement (IMPORTANT):
  167.  *
  168.  *  This C version of Dhrystone    consists of three files:
  169.  *  - dhry_global.h (this file,    containing global definitions and comments)
  170.  *  - dhry_pack_1.c (containing    the code corresponding to Ada package Pack_1)
  171.  *  - dhry_pack_2.c (containing    the code corresponding to Ada package Pack_2)
  172.  *
  173.  *  The    following "ground rules" apply for measurements:
  174.  *  - Separate compilation
  175.  *  - No procedure merging
  176.  *  - Otherwise, compiler optimizations    are allowed but    should be indicated
  177.  *  - Default results are those    without    register declarations
  178.  *  See    the companion paper "Rationale for Dhrystone Version 2"    for a more
  179.  *  detailed discussion    of these ground    rules.
  180.  *
  181.  *  For    16-Bit processors (e.g.    80186, 80286), times for all compilation
  182.  *  models ("small", "medium", "large" etc.) should be given if    possible,
  183.  *  together with a definition of these    models for the compiler    system used.
  184.  *
  185.  **************************************************************************
  186.  *
  187.  *  Dhrystone (C version) statistics:
  188.  *
  189.  *  [Comment from the first distribution, updated for version 2.
  190.  *   Note that because of language differences,    the numbers are    slightly
  191.  *   different from the    Ada version.]
  192.  *
  193.  *  The    following program contains statements of a high    level programming
  194.  *  language (here: C) in a distribution considered representative:          
  195.  *
  196.  *    assignments           52 (51.0 %)
  197.  *    control statements       33 (32.4 %)
  198.  *    procedure, function calls       17 (16.7 %)
  199.  *
  200.  *  103    statements are dynamically executed. The program is balanced with
  201.  *  respect to the three aspects:                          
  202.  *
  203.  *    -    statement type
  204.  *    -    operand    type
  205.  *    -    operand    locality
  206.  *       operand global, local, parameter, or    constant.              
  207.  *
  208.  *  The    combination of these three aspects is balanced only approximately.    
  209.  *
  210.  *  1. Statement Type:                                  
  211.  *  -----------------          number
  212.  *
  213.  *     V1 = V2               9
  214.  *     (incl.    V1 = F(..)
  215.  *     V = Constant          12
  216.  *     Assignment,           7
  217.  *     with array element
  218.  *     Assignment,           6
  219.  *     with record component
  220.  *                  --
  221.  *                  34       34
  222.  *
  223.  *     X = Y +|-|"&&"|"|" Z       5
  224.  *     X = Y +|-|"==" Constant       6
  225.  *     X = X +|- 1           3
  226.  *     X = Y *|/ Z           2
  227.  *     X = Expression,           1
  228.  *         two operators
  229.  *     X = Expression,           1
  230.  *         three operators
  231.  *                  --
  232.  *                  18       18
  233.  *
  234.  *     if ....              14
  235.  *     with "else"      7
  236.  *     without "else"      7
  237.  *         executed         3
  238.  *         not executed    4
  239.  *     for ...               7  |     counted every time
  240.  *     while ...           4  |     the loop condition
  241.  *     do ... while           1  |     is evaluated
  242.  *     switch ...           1
  243.  *     break               1
  244.  *     declaration with           1
  245.  *     initialization
  246.  *                  --
  247.  *                  34       34
  248.  *
  249.  *     P (...)    procedure call      11
  250.  *     user procedure         10
  251.  *     library procedure    1
  252.  *     X = F (...)
  253.  *           function     call       6
  254.  *     user function          5                        
  255.  *     library function     1                              
  256.  *                  --                          
  257.  *                  17       17
  258.  *                      ---
  259.  *                      103
  260.  *
  261.  *    The average number of parameters in procedure or function    calls
  262.  *    is 1.82 (not counting the    function values    as implicit parameters).
  263.  *
  264.  *
  265.  *  2. Operators
  266.  *  ------------
  267.  *                number    approximate
  268.  *                      percentage
  269.  *
  270.  *    Arithmetic         32         50.8                      
  271.  *
  272.  *     +               21       33.3                     
  273.  *     -            7       11.1                     
  274.  *     *            3        4.8
  275.  *     / (int    div)        1        1.6
  276.  *
  277.  *    Comparison         27          42.8
  278.  *
  279.  *     ==            9        14.3
  280.  *     /=            4         6.3
  281.  *     >            1         1.6
  282.  *     <            3         4.8
  283.  *     >=            1         1.6
  284.  *     <=            9        14.3
  285.  *
  286.  *    Logic              4           6.3
  287.  *
  288.  *     && (AND-THEN)        1         1.6
  289.  *     |  (OR)        1         1.6
  290.  *     !  (NOT)        2         3.2
  291.  * 
  292.  *                 --         -----
  293.  *                 63         100.1
  294.  *
  295.  *
  296.  *  3. Operand Type (counted once per operand reference):
  297.  *  ---------------
  298.  *                number    approximate
  299.  *                      percentage
  300.  *
  301.  *     Integer             175    72.3 %
  302.  *     Character          45    18.6 %
  303.  *     Pointer              12     5.0 %
  304.  *     String30               6     2.5 %
  305.  *     Array               2     0.8 %
  306.  *     Record               2     0.8 %
  307.  *                 ---       -------
  308.  *                 242       100.0 %
  309.  *
  310.  *  When there is an access path leading to the    final operand (e.g. a record
  311.  *  component),    only the final data type on the    access path is counted.          
  312.  *
  313.  *
  314.  *  4. Operand Locality:                              
  315.  *  -------------------
  316.  *                  number    approximate
  317.  *                        percentage
  318.  *
  319.  *     local variable           114          47.1 %
  320.  *     global variable            22           9.1 %
  321.  *     parameter            45          18.6 %
  322.  *      value                   23      9.5 %
  323.  *      reference               22      9.1 %
  324.  *     function    result             6           2.5 %
  325.  *     constant                55          22.7 %
  326.  *                   ---         -------
  327.  *                   242         100.0 %
  328.  *
  329.  *
  330.  *  The    program    does not compute anything meaningful, but it is    syntactically
  331.  *  and    semantically correct. All variables have a value assigned to them
  332.  *  before they    are used as a source operand.
  333.  *
  334.  *  There has been no explicit effort to account for the effects of a
  335.  *  cache, or to balance the use of long or short displacements    for code or
  336.  *  data.
  337.  *
  338.  ***************************************************************************
  339.  */
  340.  
  341. /* Compiler and    system dependent definitions: */
  342.  
  343. #ifndef    TIME
  344. #ifndef    TIMES
  345. #define    TIMES
  346. #endif
  347. #endif
  348.         /* Use "times" function    for measurement    */
  349.         /* unless explicitly defined otherwise    */
  350. #ifndef    HZ
  351. #define    HZ    60
  352. #endif
  353.         /* Use HZ = 60 for "times" function    */
  354.         /* unless explicitly defined otherwise    */
  355.  
  356. #ifdef TIMES
  357. #include <sys/types.h>
  358. #include <sys/times.h>
  359.         /* for "times" */
  360. #endif
  361.  
  362. #define    Mic_secs_Per_Second    1000000.0
  363.         /* UNIX    C returns process times    in seconds/HZ */
  364.  
  365. #ifdef    NOSTRUCTASSIGN
  366. #define    structassign(d,    s)    memcpy(&(d), &(s), sizeof(d))
  367. #else
  368. #define    structassign(d,    s)    d = s
  369. #endif
  370.  
  371. #ifdef    NOENUM
  372. #define    Ident_1    0
  373. #define    Ident_2    1
  374. #define    Ident_3    2
  375. #define    Ident_4    3
  376. #define    Ident_5    4
  377.   typedef int    Enumeration;
  378. #else
  379.   typedef    enum    {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
  380.         Enumeration;
  381. #endif
  382.     /* for boolean and enumeration types in    Ada, Pascal */
  383.  
  384. /* General definitions:    */
  385.  
  386. #include <stdio.h>
  387.         /* for strcpy, strcmp */
  388.  
  389. #define    Null 0 
  390.         /* Value of a Null pointer */
  391. #define    true  1
  392. #define    false 0
  393.  
  394. typedef    int    One_Thirty;
  395. typedef    int    One_Fifty;
  396. typedef    char    Capital_Letter;
  397. typedef    int    Boolean;
  398. typedef    char    Str_30 [31];
  399. typedef    int    Arr_1_Dim [50];
  400. typedef    int    Arr_2_Dim [50] [50];
  401.  
  402. typedef    struct record 
  403.     {
  404.     struct record *Ptr_Comp;
  405.     Enumeration       Discr;
  406.     union {
  407.       struct {
  408.           Enumeration Enum_Comp;
  409.           int          Int_Comp;
  410.           char          Str_Comp [31];
  411.           } var_1;
  412.       struct {
  413.           Enumeration E_Comp_2;
  414.           char          Str_2_Comp [31];
  415.           } var_2;
  416.       struct {
  417.           char          Ch_1_Comp;
  418.           char          Ch_2_Comp;
  419.           } var_3;
  420.       } variant;
  421.       }    Rec_Type, *Rec_Pointer;
  422.  
  423.  
  424.